#pragma once

struct WSAOVERLAPPEDEX;

class COverlappedIOCPModel :
	public INetworkLib
{
	HANDLE					m_hCompPort;

	ON_CONNECT_FUNCTOR		m_onConnectFunctor;
	ON_ACCEPT_FUNCTOR		m_onAcceptFunctor;	
	ON_DISCONNECT_FUNCTOR	m_onDisconnectFunctor;
	ON_RECV_FUNCTOR			m_onRecvFunctor;

	IAsyncSendQueue*		m_pAsyncSendQueue;

	static UINT __stdcall	workerThread( void* pArguments );
	void					postAccept( HANDLE CompletionPort, SOCKET serverSocket );
	bool					postRecv( WSAOVERLAPPEDEX* pOverlapped );
	
	bool					Send(SOCKET socket, size_t bytesSent);
public:
	COverlappedIOCPModel(void);
	virtual ~COverlappedIOCPModel(void);

	virtual bool	Initialize(ON_CONNECT_FUNCTOR onConnect
							, ON_ACCEPT_FUNCTOR onAccept
							, ON_DISCONNECT_FUNCTOR onDisconnect
							, ON_RECV_FUNCTOR onRecv		
							) override;

	virtual bool	Connect(const std::tstring& ip, WORD port) override;

	virtual bool	Send(SOCKET socket, IStreamBuffer& stream) override;

	virtual bool	Disconnect(SOCKET socket) override;

	virtual bool	Listen(const std::tstring& ip, WORD port, int backlog) override;

	virtual void	Release() override;
	


};

